package com.class05;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/servletA")
public class ServletA extends HttpServlet {
    public void doGet(HttpServletRequest request,
                      HttpServletResponse response) {
        try {
            String username = request.getParameter("username");
            System.out.println(username);
            String pwd = request.getParameter("pwd");
//            setContentType设置响应头类型和字符编码
            response.setContentType("text/html;charset=utf-8");
//            setCharacterEncoding设置响应体的字符编码
            response.setCharacterEncoding("utf-8");

            if ("张三".equals(username) && "123456".equals(pwd)) {
                response.getWriter().write("登录成功");
            } else {
                response.getWriter().write("登录失败");
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
